import Vue from 'vue'
import Router from 'vue-router'
const _import = require('./_import_' + process.env.NODE_ENV)
// in development-env not use lazy-loading, because lazy-loading too many pages will cause webpack hot update too slow. so only in production use lazy-loading;
// detail: https://panjiachen.github.io/vue-element-admin-site/#/lazy-loading

Vue.use(Router)

/* Layout */
import Layout from '../views/layout/Layout'

/** note: submenu only apppear when children.length>=1
*   detail see  https://panjiachen.github.io/vue-element-admin-site/#/router-and-nav?id=sidebar
**/

/**
* hidden: true                   if `hidden:true` will not show in the sidebar(default is false)
* alwaysShow: true               if set true, will always show the root menu, whatever its child routes length
*                                if not set alwaysShow, only more than one route under the children
*                                it will becomes nested mode, otherwise not show the root menu
* redirect: noredirect           if `redirect:noredirect` will no redirct in the breadcrumb
* name:'router-name'             the name is used by <keep-alive> (must set!!!)
* meta : {
    roles: ['admin','editor']     will control the page roles (you can set multiple roles)
    title: 'title'               the name show in submenu and breadcrumb (recommend set)
    icon: 'svg-name'             the icon show in the sidebar,
    noCache: true                if true ,the page will no be cached(default is false)
  }
**/
export const constantRouterMap = [
  { path: '/login', component: _import('login/index'), hidden: true },
  { path: '/authredirect', component: _import('login/authredirect'), hidden: true },
  { path: '/404', component: _import('errorPage/404'), hidden: true },
  { path: '/401', component: _import('errorPage/401'), hidden: true },
  {
    path: '',
    component: Layout,
    redirect: 'dashboard',
    children: [{
      path: 'dashboard',
      component: _import('dashboard/index'),
      name: 'dashboard',
      meta: { title: 'dashboard', icon: 'dashboard', noCache: true }
    }]
  },
  
]

export default new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRouterMap
})

export const asyncRouterMap = [
  
  {
    path: '/goods',
    component: Layout,
    redirect: 'noredirect',
    name: 'goods',
    meta: {
      title: '商品',
      icon: 'component'
    },
    children: [
	  { path: 'goods-list', component: _import('goods/goods-list'), name: 'goods-list', meta: { title: '商品列表' }},  
	  { path: 'goods-edit', component: _import('goods/goods-edit'), name: 'goods-edit', meta: { title: '编辑商品' }, hidden: true},  
      { path: 'category', component: _import('goods/category'), name: 'goods-category', meta: { title: '商品分类' }},    
	  { path: 'category-edit', component: _import('goods/category-edit'), name: 'goods-category-edit', meta: { title: '编辑商品分类' }},  
    ]
  },
  {
    path: '/seller',
    component: Layout,
    redirect: 'noredirect',
    name: 'seller',
    meta: {
      title: '商家',
      icon: 'form'
    },
    children: [  
	  { path: 'seller-list', component: _import('seller/seller-list'), name: 'seller-list', meta: { title: '商家列表' }},
	  { path: 'seller-edit', component: _import('seller/seller-edit'), name: 'seller-edit', meta: { title: '编辑商家' }, hidden: true},
	  { path: 'seller-admin', component: _import('seller/seller-admin'), name: 'seller-admin', meta: { title: '商家管理员' }, hidden: true},
	  { path: 'seller-admin-edit', component: _import('seller/seller-admin-edit'), name: 'seller-admin-edit', meta: { title: '编辑商家管理员' }, hidden: true},
      { path: 'seller-category', component: _import('seller/seller-category'), name: 'seller-category', meta: { title: '商家分类' }},    
	  { path: 'seller-category-edit', component: _import('seller/seller-category-edit'), name: 'seller-category-edit', meta: { title: '编辑商家分类' }, hidden: true},  
    ]
  },
  {
    path: '/order',
    component: Layout,
    redirect: 'noredirect',
    name: 'order',
    meta: {
      title: '订单',
      icon: 'excel'
    },
    children: [  
	  { path: 'order-list', component: _import('order/order-list'), name: 'order-list', meta: { title: '订单列表', icon: 'excel' }},
	  { path: 'order-edit', component: _import('order/order-edit'), name: 'order-edit', meta: { title: '订单详情' }, hidden: true}, 
    ]
  },
  {
    path: '/user',
    component: Layout,
    redirect: 'noredirect',
    name: 'user',
    meta: {
      title: '用户',
      icon: 'example'
    },
    children: [  
	  { path: 'user-list', component: _import('user/user-list'), name: 'user-list', meta: { title: '用户列表'}},
	  { path: 'user-edit', component: _import('user/user-edit'), name: 'user-edit', meta: { title: '用户详情' }, hidden: true}, 
	  { path: 'distributor-list', component: _import('distributor/distributor-list'), name: 'distributor-list', meta: { title: '配送员列表'}},
	  { path: 'distributor-edit', component: _import('distributor/distributor-edit'), name: 'distributor-edit', meta: { title: '配送员详情' }, hidden: true}, 
    ]
  },

  { path: '*', redirect: '/404', hidden: true }
]
